You are working for a company and you are asked to find the Phone Number and Email address from a long Excel file. You start scrolling the document which goes on endlessly. You know you will have to do lots of overtime to finish the work. You look at the phone to see your son’s photo. You won’t be spending family time due to the Workload. But, Suddenly you have an idea.
Python makes it really easy to do this task using Regular Expressions. We are going to try to use Regular Expression.
Note: Reproducibility is the most important thing kept in mind while writing the program.
We import the following packages
- re - Regular Expression Package
- pyperclip - It lets us work with clipboard
Steps:
- Write Regular Expression syntax
- Paste the text using pyperclip
- Print the matched result
Regular Expression are very useful but they are not without their own downsides. It is important to set the syntax of ReX(Regular Expression) right or the whole thing would go wrong.
1 | phoneRegex = re.compile(r'''( |
Next step can be modified in several ways. The most general way would be to copy the text and use pyperclip to access the clipboard.
Final step would be to print the result in desired way.
Thoughts : I definitely think it would be useful to me. I can modify it and make my web crawler. i can think of many scenario where it would be useful.
The whole program is written below for reference.
1 | ## Phone number and email extractor |